- Print
- DarkLight
Article summary
Did you find this summary helpful?
Thank you for your feedback!
// Prompt the user to enter their name
var name = prompt("What is your name?");
// Create a greeting message
var greeting = "Hello, " + name + "!";
// Display the greeting message
alert(greeting);
# Prompt the user to enter their name
name = input("What is your name? ")
# Create a greeting message
greeting = "Hello, " + name + "!"
# Display the greeting message
print(greeting)
#include <iostream>
#include <string>
int main() {
// Declare a variable to store the user's name
std::string name;
// Prompt the user to enter their name
std::cout << "What is your name? ";
std::getline(std::cin, name);
// Create a greeting message
std::string greeting = "Hello, " + name + "!";
// Display the greeting message
std::cout << greeting << std::endl;
return 0;
}
using System;
class Program
{
static void Main(string[] args)
{
// Prompt the user to enter their name
Console.Write("What is your name? ");
string name = Console.ReadLine();
// Create a greeting message
string greeting = "Hello, " + name + "!";
// Display the greeting message
Console.WriteLine(greeting);
}
}
next java:
import java.util.Scanner;
public class Greeting {
public static void main(String[] args) {
// Create a Scanner object to read input from the console
Scanner scanner = new Scanner(System.in);
// Prompt the user to enter their name
System.out.print("What is your name? ");
String name = scanner.nextLine();
// Create a greeting message
String greeting = "Hello, " + name + "!";
// Display the greeting message
System.out.println(greeting);
// Close the scanner
scanner.close();
}
}
actor Main
new create(env: Env) =>
let name = try readLine()
let greeting = "Hello, " + name + "!"
env.out.print(greeting)
Was this article helpful?